/*
Copyright 2007 Raymond Giorgi

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

package edu.pitt.CS2510.NodeActions;

import java.util.ArrayList;

import edu.pitt.CS2510.Coordinate;
import edu.pitt.CS2510.Grids.GridPiece;
import edu.pitt.CS2510.Nodes.Node;

/**
 * The base calss that all nodes (Central, Sup, and Grunt)'s actions inherit
 * from. Because all of them must update a grid at some point, that is the only
 * method included
 * 
 * @author NoOne
 * 
 */
public abstract class NodeActions implements NodeActionsInterface {
	protected Node parent = null;

	/**
	 * 'Parent' is the node that has all of the controls
	 * 
	 * @param parent
	 */
	public NodeActions(Node parent) {
		this.parent = parent;
	}

	/**
	 * Read in a list of updates and change the node's internal representation
	 * of the battlefield.
	 */
	public void updateGrid(ArrayList<Coordinate> list) {
		for (final Coordinate co : list) {
			final GridPiece piece = parent.getGrid().getBlock(co.getX(),
					co.getY());
			if (piece.isUsed()) {
				piece.setUsed(false);
			} else {
				piece.setUsed(true);
			}
		}
	}
}
